/**
 * 表单校验规范，如果符合的请直接使用。如果没有请联系达尔文前端团队增加。
 */
import supportedRegExps from './rexp'

export const validFn = (t) => {
    return {
        //isd登录名
        isdLoginName: (msg = 'isd.loginName', isRequired = true) => {
            return [
                {
                    type: 'pattern',
                    pattern: supportedRegExps.isdName,
                    message: t('validation.regExp.isdLoginName.new'),
                    trigger: ['blur']
                },
                { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //登录密码
        isdPsw: (msg = 'isd.psw', isRequired = true) => {
            return [
                {
                    type: 'pattern',
                    pattern: supportedRegExps.isdPsw,
                    message: t('validation.regExp.isdPsw'),
                    trigger: ['blur']
                },
                { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //ip地址
        ip: (msg = 'device.Ipaddress', isRequired = true) => {
            return [
                {
                    type: 'pattern',
                    pattern: supportedRegExps.ip,
                    message: t('validation.regExp', [t(msg)]),
                    trigger: ['blur']
                },
                { required: isRequired, message: t('pleaseInputIp', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //域名地址
        domain: (msg = '', isRequired = true) => {
            return [
                {
                    type: 'pattern',
                    pattern: supportedRegExps.domain,
                    message: t('validation.regExp', [t(msg)]),
                    trigger: ['blur']
                },
                { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //'必须为非负整数'
        pureNum: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.pureNum,
                message: t('validation.regExp.pureNum'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //必须为正整数
        positiveInt: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.positiveInt,
                message: t('validation.regExp.positiveInt'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //必须为1-8正整数
        positiveInt1_8: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.positiveInt1_8,
                message: t('validation.regExp.positiveInt'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //车牌号
        carNum: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.carNum,
                message: t('regExpCarNum'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //车牌号
        carNum2: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.carNum2,
                message: t('regExpCarNum2'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //'仅允许<b>-_.;()（）</b>或字母数字'
        fieldPass: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.fieldPass,
                message: t('validation.regExp.fieldPass'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //'仅允许输入文字、字母、数字'
        userLoginName: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.userLoginName,
                message: t('validation.regExp.userLoginName'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //'仅允许输入文字、字母、数字'
        treeName: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.treeName,
                message: t('validation.regExp.treeName'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        // n+m正则
        numAndNum: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.numAndNum,
                message: t('validation.regExp.numAndNum'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //'仅允许<b>文字字母数字 -_.;#（）[] 半角加号</b>和<b>全角加号</b>以及<b>字符中间有空格</b>'
        commonCharacter: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.commonCharacter,
                message: t('validation.regExp.commonCharacter'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //'仅允许<b>文字字母数字</b>'
        nationCharacter: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.nationCharacter,
                message: t('validation.regExp.nationCharacter'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        // 编码只能输入大小写字母,数字,_,-
        codeCharacter: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.codeCharacter,
                message: t('validation.regExp.codeCharacter'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        // 编码只能输入大小写字母,数字,_,-或邮箱
        codeCharacterOrEmail: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.codeCharacterOrEmail,
                message: t('validation.regExp.codeCharacterOrEmail'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /**ftp地址*/
        ftpPath: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.ftpPath,
                message: t('validation.regExpFtp'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /**mac地址*/
        mac: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.mac,
                message: t('validation.regExpMac'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /***手机号码**/
        phone: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.phone,
                message: t('validation.regExpPhone'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /***座机号码**/
        tell: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.tell,
                message: t('validation.regExpTell'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        // 描述\备注专用,在CHAR的基础上增加可以开头空格,回车换行符\uff0c\u3002为中文的
        memoCharacterEnter: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.memoCharacterEnter,
                message: t('validation.regExp.memoCharacterEnter'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        // 仅允许字母数字_字符
        sn: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.sn,
                message: t('validation.sn'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },

        //'仅允许文字字母数字-_.;#(),\/\\（）[]<br/>半角加号和、全角加号以及允许字符中间有空格',
        hikdomain: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.hikdomain,
                message: t('validation.regExp.hikdomain'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },

        // 仅允许字母或数字
        numWord: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.numWord,
                message: t('validation.regExp.numWord'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },

        // 密码必须同时包含数字和字母
        backupPass: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.backupPass,
                message: t('validation.regExp.backupPass'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },

        // 仅允许文字、字母、数字和字符中间空格
        fewCharacter: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.fewCharacter,
                message: t('validation.regExp.fewCharacter'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },

        idCard: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.idCard,
                message: t('validation.regExp.idCard'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },

        /**校验邮箱是否合法*/
        email: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.email,
                message: t('emailError'),
                trigger: 'blur'
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        gpsX: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.gpsX,
                message: t('validation.gpsX'),
                trigger: 'blur'
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        gpsY: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.gpsY,
                message: t('validation.gpsY'),
                trigger: 'blur'
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /**端口*/
        port: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.port,
                message: t('validation.port'),
                trigger: 'blur'
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /**设备名称 -中文字母数字（）*/
        deviceName: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.deviceName,
                message: t('validation.deviceName'),
                trigger: 'blur'
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /**数字编码 -数字*/
        intercomDevIndex2: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.intercomDevIndex2,
                message: t('validation.intercomDevIndex'),
                trigger: 'blur'
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /**数字编码 -数字*/
        secConDev: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.secConDevIndex,
                message: t('validation.secConDev'),
                trigger: 'blur'
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /**数字编码 -数字*/
        intercomDevIndex3: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.intercomDevIndex3,
                message: t('validation.intercomDevIndex'),
                trigger: 'blur'
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /**数字编码 -数字\-*/
        intercomDevIndex6: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.intercomDevIndex6,
                message: t('validation.intercomDevIndex'),
                trigger: 'blur'
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /**密码校验**/
        pswExp: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.pswExp,
                message: t('validation.intercomDevIndex'),
                trigger: 'blur'
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /**设备编号**/
        int10: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.int10,
                message: t('validation.int10'),
                trigger: 'blur'
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        /**0-255之间的整数**/
        numCodeExp: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.numCodeExp,
                message: t('validation.numCodeExpTip'),
                trigger: 'blur'
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        // 仅允许文字、字母、数字和下划线
        name: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.name,
                message: t('validation.regExp.name'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //
        usedLayersRules: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.usedLayers,
                message: t('validation.regExp.usedLayers'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },

        // 只能有两位小数点，不超过999999
        checkMoney: (msg = '', isRequired = true) => {
            return [{
                type: 'pattern',
                pattern: supportedRegExps.decmal3,
                message: t('validation.regExp.decmal3'),
                trigger: ['blur']
            },
            { required: isRequired, message: t('mustInput', [t(msg)]), trigger: ['blur'] }
            ]
        },
        //ip地址或者域名
        netUrl: (msg = '', isRequired = true) => {
            return [
                {
                    type: 'pattern',
                    pattern: supportedRegExps.netUrl,
                    message: t('common.netUrl'),
                    trigger: ['blur']
                },
                { required: isRequired, message: t('common.netUrl'), trigger: ['blur'] }
            ]
        }
    }
}
